package cn.techwis.service;

import cn.techwis.dto.QueryOrderDTO;
import cn.techwis.vo.PayNotifyVO;
import cn.techwis.util.WxAPIV3AesUtil;

import java.io.IOException;
import java.security.GeneralSecurityException;

/**
 * 支付回调接口
 */
public class PayNotifyService extends Tservice {


    /**
     * 微信支付回调接口
     *
     * @param payNotifyVO
     * @param key
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
    public static final QueryOrderDTO payNotify(PayNotifyVO payNotifyVO, String key) throws GeneralSecurityException, IOException {
        validateObject(payNotifyVO, PayNotifyVO.PayNotify.class);
        PayNotifyVO.ResourceVO payNotifyVOResource = payNotifyVO.getResource();
        String nonce = payNotifyVOResource.getNonce();
        String associated_data = payNotifyVOResource.getAssociated_data();
        String ciphertext = payNotifyVOResource.getCiphertext();
        QueryOrderDTO queryOrderDTO = WxAPIV3AesUtil.decryptToString(key, associated_data, nonce, ciphertext);
        return queryOrderDTO;

    }


    public static void main(String[] args) throws GeneralSecurityException, IOException {
        PayNotifyVO payNotifyVO = new PayNotifyVO();

        payNotifyVO.setId("123");
        payNotifyVO.setCreate_time("2015-05-20T13:29:35+08:00");
        payNotifyVO.setEvent_type("TRANSACTION.SUCCESS");
        payNotifyVO.setResource_type("encrypt-resource");
        payNotifyVO.setSummary("123");
        payNotifyVO.setResource(PayNotifyVO.ResourceVO.builder()
                .algorithm("AEAD_AES_256_GCM")
                .ciphertext("sadsadsadsad")
                .original_type("transaction")
                .nonce("fdasflkja484w")
                .associated_data("fdasfwqewlkja484w")
                .build());

        QueryOrderDTO fGedfdfd3554lkklkd9ljsdgrvg34cdf = payNotify(payNotifyVO, "fGedfdfd3554lkklkd9ljsdgrvg34cdf");

    }
}
